#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/fcntl.h>
#include <sys/signalfd.h>
#include <signal.h>

void sproc(int signo)
{
	printf("Handle recv %s\n", strsignal(signo));
}

int main()
{
	printf("pid = %d\n", getpid());

	sigset_t sig;
	sigemptyset(&sig);
	sigaddset(&sig, SIGUSR1);
	sigaddset(&sig, SIGUSR2);
	sigprocmask(SIG_SETMASK, &sig, NULL);

	// signal(SIGUSR1, sproc);
	// signal(SIGUSR2, sproc);

	int fd = signalfd(-1, &sig, 0);
	char buf[1024];
	struct signalfd_siginfo *sinfo = (void *)buf;

	int len = 0;
	while ((len = read(fd, buf, sizeof(buf))) > 0) {
		printf("len = %d recv sig = %s\n", len, strsignal(sinfo->ssi_signo));
	}

	return 0;
}